package com.starblink.message.mymessage.ui

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.starblink.android.basic.base.BaseViewModel
import com.starblink.android.basic.network.base.SkGqlClient
import com.starblink.rocketreserver.FetchSystemMessageQuery
import com.starblink.rocketreserver.FetchUserMessageUnreadCountV2Query
import kotlinx.coroutines.launch

class MyMessageVM : BaseViewModel() {
    // 角标默认不显示，根据加载的未读数量信息进行更新
    // 一旦某项点击查看过，不再显示角标
    var isLikeChecked = false // true表示进入过LikeMessage页面
    var isNewFollowersChecked= false
    var isCommentChecked= false
    var isSystemNotificationChecked = false
    var isActivityChecked = false

    val activityMsgLiveData: MutableLiveData<List<FetchSystemMessageQuery.FetchSystemMessage?>> =
        MutableLiveData()
    val unreadCountLiveData: MutableLiveData<FetchUserMessageUnreadCountV2Query.FetchUserMessageUnreadCountV2> =
        MutableLiveData()

    fun loadData() {
        viewModelScope.launch {
            launch {
                // 加载最新的活动消息
                val response = SkGqlClient.skQuery(
                    FetchSystemMessageQuery(
                        pageNo = 1,
                        pageSize = 1
                    ),
                    showDefaultLoading = false
                )
                if (response?.data != null && response.data!!.fetchSystemMessage != null) {
                    activityMsgLiveData.postValue(response.data!!.fetchSystemMessage!!)
                }
            }
            launch {
                // 加载未读消息数量
                val response = SkGqlClient.skQuery(
                    FetchUserMessageUnreadCountV2Query(),
                    showDefaultLoading = false
                )
                if (response?.data != null && response.data!!.fetchUserMessageUnreadCountV2 != null) {
                    unreadCountLiveData.postValue(response.data!!.fetchUserMessageUnreadCountV2)
                }
            }
        }
    }
}